home *** CD-ROM | disk | FTP | other *** search
- /*
- IC StrH.c
-
- */
-
- #include "IC StrH.h"
- #include "IC Misc Subs.h"
-
- Handle NewStrH(void){
- return NewHandleClear(sizeof(LineIndex));
- }
-
- void ReinitStrh(Handle h){
- IndexHandle ih=(IndexHandle)h;
-
- SetHandleSize(h,sizeof(LineIndex));
- **ih=0;
- }
-
- LineIndex CountStrsH(Handle h){
- IndexHandle ih=(IndexHandle)h;
-
- if (h==(Handle)0)
- return -1;
- return **ih;
- }
-
- LineIndex CountStrs(short id){
- Handle h=GetResource('STR#',id);
- LineIndex lx=-1;
-
- if (h!=(Handle)0){
- lx=CountStrsH(h);
- ReleaseResource(h);
- }
-
- return lx;
- }
-
- StringPtr GetIndStr(short strListID,short index,StringPtr str){
- GetIndString(str,strListID,index);
- return str;
- }
-
- StringPtr GetIndStrH(Handle h,LineIndex index,StringPtr s){
- LineIndex count,i;
- unsigned char* cp;
- SignedByte sb=HGetState(h);
-
- count=CountStrsH(h);
-
- if ((1<=index)&&(index<=count)){
- HLock(h);
-
- cp=(unsigned char*)(*h);
- cp+=sizeof(LineIndex);
-
- for (i=1;i<index;i++){
- cp += ((*cp)+1); // add cur str len
- }
- SetPString(s,1,cp);
-
- HSetState(h,sb);
- } else {
- s[0]=0;
- }
-
- return s;
- }
-
- void SetIndStrH(Handle h,LineIndex index,StringPtr s){
- LineIndex count,i;
- IndexHandle ih;
- long sz,pos;
- unsigned char* cp;
- SignedByte sb=HGetState(h);
-
- count=CountStrsH(h);
- sz=GetHandleSize(h);
-
- if (count<index){
- SetHandleSize(h,sz+index-count);
-
- HLock(h);
- ih=(IndexHandle)h;
- **ih=index;
-
- cp=(unsigned char*)(*h);
- cp+=sizeof(LineIndex);
-
- for (i=1;i<=count;i++){
- cp+=((*cp)+1); // add cur str len
- }
- for (i=1;i<=index-count;i++){
- *cp=0;
- cp++;
- }
- HSetState(h,sb);
-
- count=index;
- }
-
- if ((index>0)&&(index<=count)){
- HLock(h);
-
- cp=(unsigned char*)(*h);
- cp+=sizeof(LineIndex);
- pos=sizeof(LineIndex);
-
- for (i=1;i<index;i++){
- pos+=((*cp)+1);
- cp+=((*cp)+1); // add cur str len
-
- }
-
- // cp points at the string to replace
- Munger(h,pos,(Ptr)0,(*cp)+1,(Ptr)s,s[0]+1);
-
- HSetState(h,sb);
- }
- }
-
- void SetIndStr(short id,LineIndex index,StringPtr s){
- Handle h;
-
- h=GetResource('STR#',id);
- HNoPurge(h);
- SetIndStrH(h,index,s);
- HPurge(h);
- ChangedResource(h);
- WriteResource(h);
- ReleaseResource(h);
- }
-
- void DelIndStrH(Handle h,LineIndex index){
- LineIndex count,i;
- IndexHandle ih;
- long sz,pos;
- unsigned char* cp;
- SignedByte sb=HGetState(h);
-
- count=CountStrsH(h);
- sz=GetHandleSize(h);
-
- if ((index>0)&&(index<=count)){
- HLock(h);
-
- cp=(unsigned char*)(*h);
- cp+=sizeof(LineIndex);
- pos=sizeof(LineIndex);
-
- for (i=1;i<index;i++){
- pos+=((*cp)+1);
- cp+=((*cp)+1); // add cur str len
-
- }
-
- // cp points at the string to replace
- Munger(h,pos,(Ptr)0,(*cp)+1,(Ptr)(&ih),0);
-
- ih=(IndexHandle)h;
-
- (**ih)--;
-
- HSetState(h,sb);
- }
- }
-
- void DelIndStr(short id,LineIndex index){
- Handle h;
-
- h=GetResource('STR#',id);
- HNoPurge(h);
- DelIndStrH(h,index);
- HPurge(h);
- ChangedResource(h);
- WriteResource(h);
- ReleaseResource(h);
- }
-
- void InsIndStrH(Handle h,LineIndex index,StringPtr s){
- LineIndex count,i;
- IndexHandle ih;
- long sz,pos;
- unsigned char* cp;
- SignedByte sb=HGetState(h);
-
- count=CountStrsH(h);
- sz=GetHandleSize(h);
-
- if ((index>0)&&(index<=count)){
- HLock(h);
-
- cp=(unsigned char*)(*h);
- cp+=sizeof(LineIndex);
- pos=sizeof(LineIndex);
-
- for (i=1;i<index;i++){
- pos+=((*cp)+1);
- cp+=((*cp)+1); // add cur str len
-
- }
-
- // cp points at the string to replace
- Munger(h,pos,(Ptr)0,0,(Ptr)s,s[0]+1);
-
- ih=(IndexHandle)h;
-
- (**ih)++;
-
- HSetState(h,sb);
- }
- }
-
- void InsIndString(short id,LineIndex index,StringPtr s){
- Handle h;
-
- h=GetResource('STR#',id);
- HNoPurge(h);
- InsIndStrH(h,index,s);
- HPurge(h);
-
- ChangedResource(h);
- WriteResource(h);
- ReleaseResource(h);
- }
-